import numpy as np
import time, pickle
import cv2

WIDTH = 640
HEIGHT = 480

def camera_calibration(img, mtx, dist):
    h, w = img.shape[:2]
    newcameramtx, roi = cv2.getOptimalNewCameraMatrix(mtx,dist,(w,h),1,(w,h))
    dst = cv2.undistort(img,mtx,dist,None,newcameramtx)
    x,y,w,h = roi
    dst1 = dst[y:y+h,x:x+w]
    return dst1

def load_camera_params():
    with open("../configs/cam_idx.bin", 'rb') as cam_idx_file:
        cam_idx_list = pickle.load(cam_idx_file)

    return cam_idx_list
